package com.bjqh.edu.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bjqh.edu.Base.AppConstants;
import com.bjqh.edu.Bean.OpenClass;
import com.bjqh.edu.R;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/10/20.
 */

public class OpenClassAdapter extends BaseAdapter {
    private List<OpenClass.RowsBean> list;
    private Context ctx;
    private ViewHolder holder;


    public OpenClassAdapter(Context ctx, List<OpenClass.RowsBean> list) {
        this.ctx = ctx;
        this.list = list;

    }


    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View view, ViewGroup parent) {

        if (view == null) {
            view = LayoutInflater.from(ctx).inflate(R.layout.item_open_class, null);
            holder = new ViewHolder(view);
            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }
        holder.title.setText(list.get(position).getGrade()+list.get(position).getTitle());
        holder.tvTime.setText("发布时间："+AppConstants.gettimes(list.get(position).getTime()));
        if (position % 2 == 0) {
            holder.llBg.setBackgroundColor(ctx.getResources().getColor(R.color.pink));
        } else {
            holder.llBg.setBackgroundColor(ctx.getResources().getColor(R.color.grean));
        }
        return view;
    }

    static



    class ViewHolder {
        @BindView(R.id.iv_op)
        RelativeLayout ivOp;
        @BindView(R.id.title)
        TextView title;
        @BindView(R.id.ll_bg)
        LinearLayout llBg;
        @BindView(R.id.tv_time)
        TextView tvTime;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
